﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Public;


namespace DAL
{
    public class KhaiTuDAL
    {
        
        public static void InsertKhaiTu(KhaiTuPublic _ct)
        {
            KhaiTu ct = new KhaiTu();
            ct.LyDoChet = _ct.LyDoChet;
            ct.MaKT = _ct.MaKT;
            ct.NgayCap = _ct.NgayCapChungTu;
            ct.NoiChet = _ct.NoiChet;
            ct.NgayChet = _ct.NgayChet;
            ct.SoChungTu = _ct.SoChungTu;
            ct.NoiCap = _ct.NoiCapChungTu;
            ct.NguoiCap = _ct.NguoiCap;
            ct.ChucVu = _ct.ChucVu;
            ct.NguoiDangKi = _ct.NguoiDangKi;
            ct.SoBaoTu = _ct.SoBaoTu;
            ct.NgayCapBaoTu = _ct.NgayCapBaoTu;
            ct.NoiCapBaoTu = _ct.NoiCapBaoTu;
            ct.NoiOCuoiCung = _ct.NoiOCuoiCung;
            ct.CanBoDangKi = _ct.CanBoDangKi;
            ct.CanBoHoTich = _ct.CanBoHoTich;
            ct.NgayNhap = _ct.NgayNhap;
            ct.ChucVuNguoiNhan = _ct.ChucVuNguoiNhan;
            ct.NguoiNhan = _ct.NguoiNhan;
            Common.db.AddToKhaiTus(ct);
            Common.db.SaveChanges();
        }
        public static KhaiTuPublic LoadKhaiTuByMaKT(int MaKT)
        {
            var kt = Common.db.ExecuteStoreQuery<KhaiTuPublic>(@"select * from GiayChungTu where MaCT=" + MaKT);
            return kt.FirstOrDefault();
        }
        public static int CountKhaiTuByYear(int firstyear, int lastyear)
        {
            var kt = Common.db.ExecuteStoreQuery<int>(@"select count(MaKT) from KhaiTu where year(NgayNhap)>=" + firstyear + "and year(NgayNhap)<=" + lastyear);
            return kt.FirstOrDefault();
        }
    }
}
